package com.example.admin.yuejian21.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.admin.yuejian21.Bean.OrderDetail;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.Service.Service;

import it.sephiroth.android.library.picasso.Picasso;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.admin.yuejian21.Adapter.OrderAdapter.orderid;
import static com.example.admin.yuejian21.Adapter.OrderAdapter.type;

public class OrderDetailActivity extends AppCompatActivity {

    private ImageView picview;
    private TextView nameView;
    private TextView numview;
    private TextView payview;
    private TextView priceview;
    private TextView placeview;
    private TextView paytypeview;
    private TextView orderidview;
    private TextView ordertimeview;
    private OrderDetail detail;
    private TextView State;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        picview = (ImageView) findViewById(R.id.imageView2_Odpic);

        nameView = (TextView) findViewById(R.id.textView7_Odname);
        placeview = (TextView) findViewById(R.id.textView12_Odtel);
        paytypeview = (TextView) findViewById(R.id.textView34_Oway);

        ordertimeview = (TextView) findViewById(R.id.textView35_Odtime);
        orderidview = (TextView) findViewById(R.id.textView29_oid);
        payview = (TextView) findViewById(R.id.textView24_paymon);
        numview = (TextView) findViewById(R.id.textView36_0num);
        priceview = (TextView) findViewById(R.id.textView8_odprice);
      State=(TextView) findViewById(R.id.textView4_0detailstate);
        Retrofit retrofit = new Retrofit.Builder().baseUrl("http://172.24.10.175/workout/api.php/").addConverterFactory(GsonConverterFactory.create())
                .build();
        Service service = retrofit.create(Service.class);
        Call<OrderDetail> call = service.orderdetail(
                orderid,type);
        call.enqueue(new Callback<OrderDetail>() {
            @Override
            public void onResponse(Call<OrderDetail> call, Response<OrderDetail> response) {
               detail=response.body();

                if (detail != null) {
                  nameView.setText(detail.getName());
                    placeview.setText(detail.getTel());
                    priceview.setText(detail.getPrice());
                    payview.setText(detail.getPay());
                    orderidview.setText(detail.getId());
                    ordertimeview.setText(detail.getUpdate_time());
                    if(detail.getVstate().equals("0"))
                    {State.setText("未参加");}
                    else if(detail.getVstate().equals("1"))
                        State.setText("已参加");
                    else if(detail.getVstate().equals("3"))
                        State.setText("申请退款");
                    else
                        State.setText("退款成功");
                    if(detail.getPaytype().equals("1"))
                    {paytypeview.setText("微信支付");}
                    else
                        paytypeview.setText("支付宝支付");
                    numview.setText(detail.getAdultnum());

                    Picasso
                            .with(OrderDetailActivity.this)
                            .load("http://172.24.10.175/workout/Uploads/" + detail.getThumb())


                            .into(picview);


                  
                }

            }

            public void onFailure(Call<OrderDetail> call, Throwable t) {

            }
        });

    }
}
